<template>
	<view>
		<view class="justify-between section_1">
			<view class="flex-row" v-if="userInfo">
				<view class="flex-col items-center group_2" @click="()=>this.show=true">
					<image :src="changeAvatar" class="image" />
				</view>
				<text class="text">{{userInfo.nickname}}</text>
			</view>
			<view class="flex-row" v-else @click="onLogin()">
				<view class="flex-col items-center group_2">
					<image src="/static/logo.png" class="image" />
				</view>
				<text class="text">立即登录</text>
			</view>
			<image @click="goSetting" src="/static/setting.png" class="image_1" />
		</view>
		<view class="walletView">
			<view class="items-center" @click="onRecord()">
				<view class="walletTitle">账户余额</view>
				<view class="walletText">账户明细</view>
				<image class="nextImage" src="/static/right-grey.png" mode="aspectFit" />
			</view>
			<view class="items-center" style="margin-top: 30rpx;">
				<view class="walletNumber">{{userInfo.earnings||0}}</view>
				<view class="walletBtn" @click="onWithdrawal()">提现</view>
			</view>
		</view>
		<view class="flex-col orders">
			<view class="flex-col section_3">
				<text class="text_1">我的订单</text>
				<view class="divider"> </view>
				<view class="flex-row equal-division">
					<view @click="toOrder(0)" class="equal-division-item flex-col items-center">
						<image src="/static/all_order.png" class="image_2" />
						<text class="text_2">全部订单</text>
					</view>
					<view @click="toOrder(1)" class="flex-col items-center equal-division-item_1">
						<image src="/static/wait_send_order.png" class="image_3" />
						<text class="text_3">待邮寄</text>
					</view>
					<view @click="toOrder(2)" class="equal-division-item flex-col items-center group_4">
						<image src="/static/sent_order.png" class="image_4" />
						<text class="text_4">已邮寄</text>
					</view>
					<view @click="toOrder(5)" class="flex-col items-center equal-division-item_2">
						<image src="/static/complete_order.png" class="image_5" />
						<text class="text_5">已完成</text>
					</view>
				</view>
			</view>
			<view>
				<!-- <drag-button :isDock="false" :existTabBar="true" @btnClick="btnClick" /> -->
			</view>
		</view>
		<view class="tips">
			<h2 style="font-weight: bold;font-size: 34rpx;">如需寄卖酒水，快递请填写以下信息：</h2>
			<view class="address cells">
				<view class="left">回收地址：</view>
				<view class="right">
					{{info.receive_add}}
				</view>
			</view>
			<view class="user cells">
				<view class="left">收件人姓名：</view>
				<view class="right">
					{{info.receive_name}}
				</view>
			</view>
			<view class="phone cells">
				<view class="left">收件人电话：</view>
				<view class="right">
					{{info.receive_phone}}
				</view>
			</view>
			<!-- <rich-text :nodes="notice"></rich-text> -->
			<view class="copy" style="text-align: right;" @click="copy">
				点击复制 <u-icon name="order" size="32" color="#333"></u-icon>
			</view>
		</view>
		<u-popup v-model="show" mode="center" border-radius="20" width="500" height="530" :closeable="true">
			<view class="box">
				<view class="title">
					修改用户信息
				</view>
				<view class="avatar" @click="uploadAvatar()">
					<image :src="changeAvatar" style="width: 108rpx; " mode="widthFix" />
				</view>
				<view class="name cell">
					<view class="left">
						姓名
					</view>
					<view class="ipt">
						<input type="text" placeholder="请输入姓名" v-model="userInfo.nickname" />
					</view>
				</view>
				<view class="name cell">
					<view class="left">
						电话号码
					</view>
					<view class="ipt">
						<input type="text" placeholder="请输入电话号码" v-model="userInfo.phone" />
					</view>
				</view>
				<view class="submit" @click="save">
					提交
				</view>

			</view>
		</u-popup>
		<u-tabbar :list="tabbar"></u-tabbar>
	</view>
</template>

<script>
	import {
		tiao,
		toast
	} from '@/utils/common.js'
	import {
		updateInfo,
		getUserInfo,
		getSystem
	} from '@/api/index.js'
	export default {
		data() {
			return {
				current: 1,
				userInfo: "",
				show: false,
				changeAvatar: "",
				tabbar: [{
						"pagePath": "/pages/index/index",
						"iconPath": "/static/tabbar/tab2.png",
						"selectedIconPath": "/static/tabbar/tab1.png",
						"text": "回收寄卖"
					},
					{
						"pagePath": "/pages/mine/mine",
						"iconPath": "/static/tabbar/tab4.png",
						"selectedIconPath": "/static/tabbar/tab3.png",
						"text": "我的"
					}
				],
				info: {
					// address: "贵州省贵阳市南明区.油榨街理想城A2栋.菜鸟驿站。",
					// name: "陆志刚",
					// phone: "15085913897"
				},
				notice:"",
				description:""
			}
		},


		onLoad() {
			getSystem({
				key: 'receive'
			}).then(res => {
				console.log("通知", res);
				this.info = JSON.parse(res.data.value)
				// this.description = res.data.description
			
			})
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				this.userInfo = ""
				let token = uni.getStorageSync("access_token") || ''
				if (token) {
					getUserInfo().then(res => {
						this.userInfo = res.data
						this.changeAvatar = res.data.format_avatar
					})
				} else {
					uni.showModal({
						title: "提示",
						content: "你还没有登录,是否去登录",
						cancelText: "取消",
						confirmText: "确定",
						success(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/login/login'
								})
							}

						}
					})
				}
			},
			onLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				});
			},
			copy() {
				uni.setClipboardData({
					data: "收件人:"+this.info.receive_name+"收件人电话:"+this.info.receive_phone+"地址:"+this.info.receive_add,// e是你要保存的内容
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})

			},
			onRecord() {
				tiao('/pages/balance-record/balance-record')

			},
			onWithdrawal() {
				tiao('/pages/withdrawal/withdrawal', {
					price: this.userInfo.earnings
				})

			},
			onApply() {
				tiao('/pages/apply-partner/apply-partner')

			},
			toOrder(index) {
				tiao('/pages/orders/orders', {
					index
				})

			},
			goSetting() {
				tiao('/pages/setting/setting')
			},
			save() {
				let {
					avatar,
					nickname,
					phone
				} = this.userInfo
				updateInfo({
					avatar,
					phone,
					nickname
				}).then(res => {
					toast("修改成功")
					this.userInfo = res.data
					this.changeAvatar = res.data.format_avatar
					this.show = false
				})
			},
			uploadAvatar() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					success: (res) => {
						const tempFilePaths = res.tempFilePaths //图片临时数组
						console.log(tempFilePaths)
						uni.uploadFile({
							//请求的url接口地址
							url: 'https://zjjiuye.cn/api/public/images/upload',
							fileType: 'image', //图片类型
							filePath: tempFilePaths[0], //哪张图片
							name: 'file', //对应接口的文件名称
							header: { //请求头
								"Content-Type": "multipart/form-data"
							},
							success: (res) => {
								//成功的回调
								//一般用于重新获取数据渲染页面
								console.log(res);
								console.log("上传", JSON.parse(res.data))
								let data = JSON.parse(res.data)
								this.userInfo.avatar = data.data
								this.changeAvatar = tempFilePaths[0]
								toast("上传成功")
							},
							fail: (err) => {
								//失败的回调
								console.log(err)
							}
						})
					}
				})

			}
		}
	}
</script>

<style scoped lang="scss">
	.apply {
		padding: 30rpx;
		background-image: linear-gradient(296.9deg, rgb(144, 244, 105) 0%, rgb(0, 199, 133) 100%);
		border-radius: 10rpx;
		margin: 0 30rpx;
		margin-top: 30rpx;
		font-size: 36rpx;
		text-align: center;
		font-weight: bold;
		color: #ffffff;
		font-style: italic;
	}

	.section_1 {
		padding: 150rpx 30rpx 30rpx;
		color: rgb(255, 255, 255);
		font-size: 36rpx;
		font-weight: 500;
		line-height: 50rpx;
		white-space: nowrap;
		background-image: linear-gradient(296.9deg,
				rgb(144, 244, 105) 0%,
				rgb(144, 244, 105) -141.8%,
				rgb(0, 199, 133) 120.08%,
				rgb(0, 199, 133) 100%);
		border-radius: 0px 0px 0px 50rpx;

		.image_1 {
			margin-right: 20rpx;
			align-self: center;
			width: 36rpx;
			height: 33rpx;
		}

		.group_2 {
			width: 110rpx;
			height: 110rpx;
			position: relative;

			.image {
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
				background: #fff;
			}

			.section_2 {
				border-radius: 50%;
				width: 110rpx;
				height: 110rpx;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
				position: absolute;
				border: solid 3rpx rgb(255, 255, 255);
			}
		}

		.text {
			font-size: 36rpx;
			font-weight: bold;
			margin-left: 20rpx;
			align-self: center;
		}
	}

	.tips {
		margin: 0px 30rpx;
		margin-top: 30rpx;
		padding: 30rpx 30rpx 40rpx;
		display: flex;
		flex-direction: column;
		background-color: rgb(255, 255, 255);
		box-shadow: 0px 2rpx 20rpx 0px rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		height: 280rpx;
		justify-content: space-around;
	}

	.walletView {
		margin: 0px 30rpx;
		margin-top: 30rpx;
		padding: 30rpx 30rpx 40rpx;
		display: flex;
		flex-direction: column;
		background-color: rgb(255, 255, 255);
		box-shadow: 0px 2rpx 20rpx 0px rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		z-index: 100;

		.walletTitle {
			flex: 1;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
		}

		.walletText {
			font-weight: 400;
			font-size: 24rpx;
			color: #ABA9A2;
		}

		.nextImage {
			width: 20rpx;
			height: 20rpx;
		}

		.walletNumber {
			font-weight: bold;
			font-size: 38rpx;
			color: #333333;
		}

		.walletBtn {
			font-size: 26rpx;
			background: #00C785;
			border-radius: 30rpx;
			color: #ffffff;
			width: 128rpx;
			height: 50rpx;
			line-height: 50rpx;
			text-align: center;
			border-radius: 25rpx;
			margin-left: 30rpx;
		}
	}

	.orders {
		padding: 30rpx 30rpx 55rpx;

		.section_3 {
			padding: 25rpx 0 21rpx;
			background-color: rgb(255, 255, 255);
			box-shadow: 0px 2rpx 20rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;

			.text_1 {
				margin-left: 30rpx;
				color: rgb(34, 34, 34);
				font-size: 30rpx;
				font-weight: 500;
				line-height: 42rpx;
				white-space: nowrap;
			}

			.divider {
				margin-top: 25rpx;
				background-color: rgb(238, 238, 238);
				height: 2rpx;
			}

			.equal-division {
				margin-top: 19rpx;
				color: rgb(68, 68, 68);
				font-size: 24rpx;
				line-height: 33rpx;
				white-space: nowrap;

				.equal-division-item {
					flex: 1 1 156rpx;
					padding: 11rpx 0 10rpx;

					.image_2 {
						width: 37rpx;
						height: 44rpx;
					}

					.text_2 {
						margin-top: 14rpx;
					}

					.image_4 {
						width: 45rpx;
						height: 45rpx;
					}

					.text_4 {
						margin-top: 13rpx;
					}
				}

				.equal-division-item_1 {
					margin-left: 22rpx;
					padding: 12rpx 0 10rpx;
					flex: 1 1 156rpx;

					.image_3 {
						width: 43rpx;
						height: 43rpx;
					}

					.text_3 {
						margin-top: 14rpx;
					}
				}

				.group_4 {
					margin-left: 22rpx;
				}

				.equal-division-item_2 {
					margin-left: 22rpx;
					padding: 10rpx 0;
					flex: 1 1 156rpx;

					.image_5 {
						width: 45rpx;
						height: 46rpx;
					}

					.text_5 {
						margin-top: 13rpx;
					}
				}
			}
		}

	}

	.box {
		width: 500rpx;
		height: 530rpx;
		box-sizing: border-box;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 20rpx;

		.title {
			text-align: center;
			margin: 30rpx;
			font-size: 32rpx;
			color: 333;
		}

		.avatar {
			width: 108rpx;
			height: 108rpx;
			overflow: hidden;
			background-color: #f5f5f5;
			border-radius: 50%;
			margin: 30rpx auto;
		}

		.cell {
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			.left {
				width: 120rpx;
				height: 40rpx;
			}

			.ipt {
				width: 320rpx;
				height: 60rpx;
				box-sizing: border-box;
				padding: 10rpx;
				margin-left: 10rpx;
				background-color: #f5f5f5;
			}
		}

		.submit {
			position: absolute;
			bottom: 30rpx;
			width: 120rpx;
			height: 60rpx;
			left: 190rpx;
			text-align: center;
			background-color: #00C785;
			line-height: 60rpx;
		}
	}

	.cells {
		display: flex;
		margin-top: 20rpx;


		.left {
			min-width: 160rpx;
			max-width: 180rpx;
		}

		.right {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			max-width: 440rpx;
		}
	}
</style>